package com.echo.code.arithmetic.chapter09;

import java.util.Objects;

/**
 * Created by baiyap on 2018/8/16.
 */
public class StringUtils {

  public static boolean isEmpty(String str) {
    return Objects.isNull(str) || str.length() == 0;
  }

  public static boolean nonEmpty(String str) {
    return !isEmpty(str);
  }

  public static void requireNonEmpty(String str) {
    if (isEmpty(str)) {
      throw new NullPointerException();
    }
  }

  public static void requireNonEmpty(String str, String msg) {
    if (isEmpty(str)) {
      throw new NullPointerException(msg);
    }
  }

  public static void requireNonNull(String str) {
    if (Objects.isNull(str)) {
      throw new NullPointerException();
    }
  }

  public static void requireNonNull(String str, String msg) {
    if (Objects.isNull(str)) {
      throw new NullPointerException(msg);
    }
  }
}
